const {
  DataTypes
} = require('sequelize');
module.exports = sequelize => {
  const attributes = {
    roleId: {
      type: DataTypes.BIGINT,
      allowNull: false,
      defaultValue: null,
      comment: "角色ID",
      primaryKey: true,
      field: "role_id",
      autoIncrement: false,
      references: {
        key: "id",
        model: "sys_role_model"
      }
    },
    menuId: {
      type: DataTypes.BIGINT,
      allowNull: false,
      defaultValue: null,
      comment: "菜单ID",
      primaryKey: true,
      field: "menu_id",
      autoIncrement: false,
      references: {
        key: "id",
        model: "sys_menu_model"
      }
    }
  };
  const options = {
    tableName: "sys_role_menu",
    comment: "",
    indexes: []
  };
  const SysRoleMenuModel = sequelize.define("sys_role_menu_model", attributes, options);

  SysRoleMenuModel.associate = function(models) {
    // 与菜单表建立关联
    SysRoleMenuModel.belongsTo(models.sys_menu_model, {
      foreignKey: 'menu_id',
      targetKey: 'id'
    });
    // 与角色表建立关联
    SysRoleMenuModel.belongsTo(models.sys_role_model, {
      foreignKey: 'role_id',
      targetKey: 'id'
    });
  };

  return SysRoleMenuModel;
};